package org.zhuxian.cn.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.zhuxian.cn.entity.Talisman;
import org.zhuxian.cn.result.JsonResult;
import org.zhuxian.cn.service.TalismanService;

import java.util.List;

@RestController
@RequestMapping("/talisman")
@Api(tags = "法宝管理", description = "法宝相关接口")
public class TalismanController {

    @Autowired
    private TalismanService talismanService;

    @ApiOperation(value = "添加法宝", notes = "添加新的法宝信息到系统")
    @PostMapping("/add")
    public JsonResult createTalisman(@ApiParam(value = "法宝信息") @RequestBody Talisman talisman) {
        boolean result = talismanService.createTalisman(talisman);
        return new JsonResult(200, "OK");
    }

    @ApiOperation(value = "更新法宝", notes = "更新已存在的法宝信息")
    @PostMapping("/update")
    public JsonResult updateTalisman(@ApiParam(value = "法宝信息") @RequestBody Talisman talisman) {
        boolean result = talismanService.updateTalisman(talisman);
        return new JsonResult(200, "OK");
    }

    @ApiOperation(value = "删除法宝", notes = "根据ID删除法宝信息")
    @PostMapping("/delete/{id}")
    public JsonResult deleteTalisman(@ApiParam(value = "法宝ID") @PathVariable Integer id) {
        boolean result = talismanService.deleteTalisman(id);
        return new JsonResult(200, "OK");
    }

    @ApiOperation(value = "获取法宝", notes = "根据ID获取法宝详细信息")
    @GetMapping("/get/{id}")
    public JsonResult getTalismanById(@ApiParam(value = "法宝ID") @PathVariable Integer id) {
        Talisman talisman = talismanService.getTalismanById(id);
        return new JsonResult(200, "OK", talisman);
    }

    @ApiOperation(value = "获取所有法宝", notes = "获取系统中所有法宝的列表")
    @GetMapping("/all")
    public JsonResult getAllTalismans() {
        List<Talisman> talismans = talismanService.getAllTalismans();
        return new JsonResult(200, "OK", talismans);
    }
}